Event.observe(window, 'load', function() {

  Event.observe('emailsettings_form', 'submit', emailsettings);

});

	function alertContents(http_request) {
		var xmlDocument = http_request.responseXML;
//alert(
//http_request.responseText
//);
		var body = xmlDocument.getElementsByTagName('message')[0].attributes.getNamedItem("body").value;
		var redirect_to = xmlDocument.getElementsByTagName('message')[0].attributes.getNamedItem("redirect_to").value;
        alert(
        body
        );

        window.location = redirect_to;
   }
   
   function emailsettings(e) {
        Event.stop(e);
        $("submit.emailSettings").disabled=true;
        $("submit.emailSettings").value='wait...';

		var url = '/ajax/emailsettings.aspx';
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: $('emailsettings_form').serialize(true),
				onComplete: alertContents,
				onFailure: function(){ alert('Something went wrong...') }
			});
        return false;
   }
